<?php
// +----------------------------------------------------------------------
// |管理员相关操作类
// +----------------------------------------------------------------------
// | Copyright (c) 2010 旋风工作室 All rights reserved.
// +----------------------------------------------------------------------
// | Author：XF.Zhoujz
// +----------------------------------------------------------------------

class SettingsAction extends Action{
	//数据列表
	public function Index(){
		$this->validate();
	    $Systems = D('Settings');  			//实例化model
	    $result = $Systems->find();
	    $this->assign("result", $result['index']); 
        $this->assign("color", $result['color']); 
	    $this->display('index'); 
	 }

     //显示首页编辑器
     public function index_edit(){
		$this->validate();
	    $Systems = D('Settings');  			//实例化model
	    $result = $Systems->field('index')->find();
	    $this->assign("result", $result['index']); 
	    $this->display(); 
     }
     
     //编辑首页
     public function edit_index(){
        $this->validate();
        import("@.ORG.Input");
        $Settings = D('Settings');
        $data['index'] = Input::getVar($_POST['content']);
        if(false!==$Settings->where('1 = 1 ')->save($data)){
            $this->assign('jumpUrl','Index');
			$this->success('数据添加成功！');
        }else{
            echo $Settings->getError();exit;
            $this->error($Settings->getDbError());
        }
     }
     
     //编辑首页
     public function updatecolor(){
        $this->validate();
        import("@.ORG.Input");
        $Settings = D('Settings');
        $data['color'] = Input::getVar($_POST['color']);
        if(false!==$Settings->where('1 = 1 ')->save($data)){
            $this->ajaxback('','更新背景色成功！',1);
        }else{
             $this->ajaxback($data,$Settings->getLastSql().'更新背景色失败！',0);
        }
     }
     
	//登陆信息验证
	public function validate(){
		if(empty($_SESSION['admin'])){
			$this->redirect('Public/login');
		}
	}
    
    //输出ajax结果
    private function ajaxback($data,$msg,$states){
        $result = array(
            'data' => $data,
            'msg' => $msg,
            'states' => $states
        );
        echo json_encode($result);
    }

}
?>